package com.jlcindia.dao;

import com.jlcindia.hibernate.Customer;
import com.jlcindia.util.CHibernateTemplate;
import com.jlcindia.util.CustomerTO;

public class HibernateCustomerDAO implements CustomerDAO {

	@Override
	public int addCustomer(CustomerTO cto) {
		Customer cust = new Customer(cto.getCname(), cto.getEmail(), cto.getPhone(), cto.getCity(), cto.getStatus());
		Integer it = (Integer)CHibernateTemplate.saveObject(cust);
		return it.intValue();
	}

	@Override
	public void updateCustomer(CustomerTO cto) {
		Customer cust = new Customer(cto.getCid(),cto.getCname(), cto.getEmail(), cto.getPhone(),  cto.getCity(), cto.getStatus());
		CHibernateTemplate.updateObject(cust);
		
	}

	@Override
	public void deleteCustomer(int cid) {
		CHibernateTemplate.deleteObject(Customer.class,cid);
		
	}

	@Override
	public CustomerTO getCustomerByCid(int cid) {
		Customer cust = (Customer)CHibernateTemplate.loadObject(Customer.class,cid);
		CustomerTO cto = new CustomerTO(cust.getCid(),cust.getCname(), cust.getEmail(), cust.getPhone(), cust.getCity(), cust.getStatus()); 
		return cto;
	}

}
